<template>
    <div class="flow">
        <!-- 调动人数 / 离职人数 -->
        <div class="head">
          <!-- 调动人数 -->
          <div class="diaodong">
            <img src="../../../../../../static/img/rl/ld_diaodong.png" class="left" />
            <div class="right">
              <p>调动人数</p>
              <p>{{totalNumber}}</p>
            </div>
          </div>
          <em></em>
          <!-- 离职人数 -->
          <div class="lizhi">
            <img src="../../../../../../static/img/rl/ld_lizhi.png" class="left" />
            <div class="right">
              <p>离职人数</p>
              <p>{{dimissionNum}}</p>
            </div>
          </div>
        </div>
        <!-- 人员流动占比 -->
        <div class="flowProportion">
          <div class="border">
            <span>人员流动占比</span>
          </div>
          <div class="top">
            <!-- 各版块调动人数占比 -->
            <div class="transferNum">
              <block-title><span slot="title">各版块调动人数占比</span></block-title>
              <div class="chart">
                <pie-chart v-model="theNumberOfData" :chartStyle="'width:100%;min-height:460px;'" :option="pieChartOption"></pie-chart>
              </div>
            </div>
            <em></em>
            <!-- 各版块离职率 -->
            <div class="separationRate">
              <block-title><span slot="title">各版块离职率</span></block-title>
              <div class="chart">
                <peak-chart v-model="peakData" :option="peakOption" :chartStyle="'width:100%;min-height:320px;'"></peak-chart> 
                <!-- <bar-chart v-model="peakData" :chartStyle="'width:100%;min-height:400px;'"></bar-chart>  -->
              </div>
            </div>
          </div>
          <div class="bot">
            <!-- 离职分析-板块 -->
            <div class="analysis turnover">
              <block-title><span slot="title">离职分析-板块</span></block-title>
              <div class="chart">
                <ball-chart v-model="plateDimissionArr"></ball-chart>
              </div>
            </div>
            <em></em>
            <!-- 离职分析-司龄 -->
            <div class="analysis">
              <block-title><span slot="title">离职分析-司龄</span></block-title>
              <div class="chart">
                <pie-chart v-model="seniorityArr" :option="seniorityOption" :chartStyle="'min-height:280px;'"></pie-chart>
              </div>
            </div>
            <em></em>
            <!-- 离职分析-职级 -->
            <div class="analysis">
              <block-title><span slot="title">离职分析-职级</span></block-title>
              <div class="chart">
                <pie-chart v-model="overallData" :option="shopOrderOption" :chartStyle="'min-height:280px;'"></pie-chart>
              </div>
            </div>
            <em></em>
            <!-- 离职分析-考核 -->
            <div class="analysis">
              <block-title><span slot="title">离职分析-考核</span></block-title>
              <div class="chart">
                <double-ball v-model="dimissionData"></double-ball>
              </div>
            </div>
          </div>
        </div>
    </div>
</template>
<script>
import blockTitle from "@/components/rl/blockTitle";
import pieChart from "@/components/Charts/pieChart";
import doubleBall from "@/components/Charts/doubleBall.vue";
import peakChart from "@/components/Charts/peakChart";
import barChart from "@/components/Charts/barChart";
import ballChart from "@/components/Charts/ballChart.vue";
import {
  // HumanResourcesGetDataByDoubleTarget,
  GetDataByTarget
} from "@/api/rl/index";
export default {
  components: {
    blockTitle,
    doubleBall,
    peakChart,
    ballChart,
    barChart,
    pieChart
  },
  data() {
    return {
      totalNumber: 0, // 调动人数
      dimissionNum: [], // 离职人数
      plateDimissionArr: [],
      peakData: [],
      dimissionData: {}, // 离职分析-考核
      // 离职-司龄
      seniorityArr: [],
      seniorityOption: {
        color: ["#EE3F86", "#29AAE1", "#FAAF3B", "#22B473", "#435EFF"],
        radius: ["35%", "50%"],
        center: ["50%", "35%"],
        // roseType: "radius",
        startAngle: 250,
        formatter: function(value) {
          return (
            "{value|" + value.name + "}"
            // "{value|" + value.name + "}" + "\n" + "{large|" + value.value + "}"
          );
        },
        hidePieMargin: true,
        showLine: true,
        showLabel: true,
        legend: {
          show: false
        }
      },
      overallData: [],
      shopOrderOption: {
        color: ["#7F47DC", "#EE3F86", "#FAAF3B"],
        radius: ["35%", "50%"],
        center: ["50%", "35%"],
        // roseType: "radius",
        startAngle: 250,
        formatter: function(value) {
          return (
            "{value|" + value.name + "}"
            // "{value|" + value.name + "}" + "\n" + "{large|" + value.value + "}"
          );
        },
        hidePieMargin: true,
        showLine: true,
        showLabel: true,
        legend: {
          show: false
        }
      },
      theNumberOfData: [],
      pieChartOption: {
        color: [
          "#22B473",
          "#29AAE1",
          "#FAAF3B",
          "#435EFF",
          "#EE3F86",
          "#F05A24",
          "#22B473",
          "#435EFF",
          "#7F47DC"
        ],
        radius: ["0%", "50%"],
        center: ["50%", "32%"],
        roseType: "radius",
        startAngle: 250,
        formatter: function(value) {
          return "{value|" + value.name + "}";
        },
        hidePieMargin: false,
        showLine: true,
        showLabel: true,
        legend: {
          show: false
        }
      }
    };
  },
  mounted() {
    this.fetchData();
  },
  methods: {
    // 离职分析-司龄
    async fetchSeniorityArr() {
      try {
        var params = {
          timeQueryType: "48003",
          queryType: "10007"
        };
        var res = await GetDataByTarget(params);
        if (res.data.code === "0") {
          var result = res.data.result;
          this.$set(this, "seniorityArr", result);
        }
      } catch (e) {
        console.log(e);
      }
    },
    // 离职分析-职级
    async fetchOverallData() {
      try {
        var params = {
          timeQueryType: "48003",
          queryType: "10002"
        };
        var res = await GetDataByTarget(params);
        if (res.data.code === "0") {
          var result = res.data.result;
          this.$set(this, "overallData", result);
        }
      } catch (e) {
        console.log(e);
      }
    },
    // 各版块离职率
    async fetchPeakData() {
      try {
        var params = {
          timeQueryType: "48003",
          queryType: "10022"
        };
        var res = await GetDataByTarget(params);
        if (res.data.code === "0") {
          var result = res.data.result;
          this.$set(this, "peakData", result);
        }
      } catch (e) {
        console.log(e);
      }
    },
    // 离职分析-板块
    async fetchPlateDimissionArr() {
      try {
        var params = {
          timeQueryType: "48003",
          queryType: "10011"
        };
        var res = await GetDataByTarget(params);
        if (res.data.code === "0") {
          var result = res.data.result;
          var number = 0;
          result.forEach(element => {
            number += element.value;
          });
          this.$set(this, "dimissionNum", number);
          this.$set(this, "plateDimissionArr", result);
        }
      } catch (e) {
        console.log(e);
      }
    },
    // // 人数占比、
    async fetchTheNumberOfData() {
      try {
        var params = {
          timeQueryType: "48004",
          queryType: "10023"
        };
        var res = await GetDataByTarget(params);
        if (res.data.code === "0") {
          var result = res.data.result;
          this.$set(this, "theNumberOfData", result);
          var totalNumber = 0;
          result.forEach(element => {
            totalNumber += element.value;
          });
          this.$set(this, "totalNumber", totalNumber);
        }
      } catch (e) {
        console.log(e);
      }
    },
    fetchData() {
      this.fetchSeniorityArr(); // 离职分析-司龄
      this.fetchOverallData(); // 离职分析-职级
      this.fetchPlateDimissionArr(); // 离职分析-板块
      this.fetchPeakData(); // 各版块离职率
      this.fetchTheNumberOfData(); // 人数占比
      var a = {
        list: [
          {
            name: "通过",
            value: 666
          },
          {
            name: "不通过",
            value: 333
          }
        ],
        total: 999
      };
      this.$set(this, "dimissionData", a);
      // this.$set(this, "peakData", [
      //   {
      //     name: "xxx",
      //     value: 555
      //   },
      //   {
      //     name: "wwww",
      //     value: 111
      //   },
      //   {
      //     name: "eee",
      //     value: 222
      //   },
      //   {
      //     name: "rrr",
      //     value: 333
      //   },
      //   {
      //     name: "ttt",
      //     value: 444
      //   }
      // ]);
    }
  }
};
</script>

<style lang="scss">
@import "../../../../../styles/base/_parameters";
.turnover {
  .chart {
    div {
      & > div {
        display: flex;
        flex-direction: column;
        p {
          height: 15px;
          font-size: 12px;
          &:nth-of-type(1) {
            white-space: nowrap;
          }
          &:nth-of-type(2) {
            @include din(16px);
          }
        }
      }
    }
  }
}
</style>


<style scoped lang="scss">
@import "../../../../../styles/base/_parameters";
$color: #29aae1;
$titleColor: #faaf3b;
$contentColor: #22b473;
$lineBack: rgba(#29aae1, 0.2);

.flow {
  @include absoluteAllSides(33, 0, 26, 0, 1);

  .head {
    display: flex;
    align-items: center;
    height: 138px;
    em {
      display: inline-block;
      width: 1px;
      height: 70px;
      background-color: $lineBack;
    }
    .left {
      width: 65px;
      height: 69px;
    }
    .right {
      margin-left: 16px;
      font-size: 26px;
      p:nth-of-type(2) {
        @include din(42px);
        line-height: 1;
      }
    }
    .diaodong,
    .lizhi {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 50%;
    }
    .diaodong {
      .right {
        color: $contentColor;
      }
    }
    .lizhi {
      .right {
        color: $titleColor;
      }
    }
  }
  .border {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 55px;
    line-height: 55px;
    color: $color;
    font-size: 22px;
    background: url("../../../../../../static/img/rl/border2.png") left center
      no-repeat;
    background-size: 100%;
    span {
      position: absolute;
      left: 120px;
      z-index: 1;
    }
  }
  .flowProportion {
    .top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 42px;
      margin-top: 20px;
      .transferNum,
      .separationRate {
        width: calc(100% / 2 - 38px);
      }
      em {
        display: inline-block;
        width: 1px;
        height: 300px;
        margin: 0 38px;
        background-color: $lineBack;
      }
      .chart {
        height: 290px;
        margin-top: 36px;
      }
    }
    .bot {
      display: flex;
      align-items: center;
      padding: 0 21px;
      margin-top: 34px;
      .analysis {
        width: calc(100% / 4 - 22px);
        .chart {
          position: relative;
          height: 210px;
        }
      }
      em {
        display: inline-block;
        width: 1px;
        height: 210px;
        margin: 0 22px;
        background-color: $lineBack;
      }
    }
  }
}
</style>
